package com.macrohard.admin.controller;

import com.macrohard.admin.dto.UpdateRelationDTO;
import com.macrohard.admin.service.SysRelationService;
import com.macrohard.common.base.response.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@RestController
@RequiredArgsConstructor
@RequestMapping("relation")
@Validated
@Api(tags = "菜单关系接口")
@Slf4j
public class RelationController {
	private final SysRelationService relationService;

	@PostMapping
	@ApiOperation("修改教师拥有的菜单")
	public R update(@RequestBody UpdateRelationDTO dto) {
		if (Objects.isNull(dto.getTid()) || Objects.isNull(dto.getIds())) {
			return R.error(500, "参数不能为空");
		}
		return R.wrapEffectResult(relationService.updateByMenuIds(dto.getTid(), dto.getIds()));
	}
}
